package system.impl;

import client.Client;
import client.ClientNavigator;

public class ClientSystemImpl {
	
	public enum CLIENT_TYPE { WEB, COMMAND_LINE, SWING }
	
	private Client client;

	public ClientSystemImpl(API api, ClientNavigator navigator, Object user) throws Exception {
		setClient(api.createClient(navigator, user));
	}
	public ClientSystemImpl(API api, ClientNavigator navigator) throws Exception {
		this(api, navigator, null);
	}
	public ClientSystemImpl(API api, CLIENT_TYPE clientType, Object user) throws Exception {
		setClient(api.createClient(getClientClass(clientType), user));
	}
	public ClientSystemImpl(API api, CLIENT_TYPE clientType) throws Exception {
		this(api, clientType, null);
	}
	
	public void start() {
		getClient().getNavigator().start();
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		//System.out.println("SetClient at " + this + " to " + client);
		if(client == null)
			new Exception("SetClient " + client).printStackTrace();
		this.client = client;
	}	

	private static Class<? extends ClientNavigator> getClientClass(CLIENT_TYPE clientType) {
		if(clientType.equals(CLIENT_TYPE.COMMAND_LINE))
			return CommandLineClientNavigator.class;
		if(clientType.equals(CLIENT_TYPE.WEB))
			return SingleRequestClientNavigator.class;
		if(clientType.equals(CLIENT_TYPE.SWING))
			return SwingClientNavigator.class;
		return ClientNavigator.class;
	}
}
